<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<style type="text/css">
    /**地图列表**/
    .field_list_wrap_big {
        width: 260px;
        position: absolute;
        top: 0;
        bottom: 0;
        right: -242px;
        text-align: left;
        -webkit-transition: right 0.3s;
        -moz-transition: right 0.3s;
        transition: right 0.3s;
    }

    .field_list_wrap_big.open {
        right: 0;
    }

    .field_list_wrap {
        width: 240px;
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 1;
        border: 1px solid #cacaca;
        background: rgba(255, 255, 255, 0.8);
    }

    .field_list_wrap .top {
        height: 35px;
        overflow: hidden;
        line-height: 40px;
        padding-left: 10px;
        font-size: 14px;
        color: #444;
    }

    .field_list_wrap .field_box {
        height: 467px;
        overflow-y: auto;
    }

    .field_list_wrap .field_li a {
        display: block;
        position: relative;
        padding-top: 10px;
    }

    .field_list_wrap .field_li a.current, .field_list_wrap .field_li a:hover, .current_hover {
        background: #f2fbff;
    }

    .field_list_wrap .field_li .box {
        border-bottom: 1px solid #ddd;
        padding: 0 5px 10px 25px;
        overflow: hidden;
        margin-left: 10px;
    }

    .field_list_wrap .field_li .border_n {
        border: none;
    }

    .field_list_wrap .field_li .number {
        position: absolute;
        top: 8px;
        left: 10px;
        width: 17px;
        height: 24px;
        line-height: 20px;
        text-align: center;
        font-size: 12px;
        color: #fff;
        background: url('${ctx}/image/activity/address_bg.png') no-repeat;
    }

    .field_list_wrap .field_li h2 {
        line-height: 20px;
        font-size: 14px;
        color: #0099e9;
        margin-bottom: 5px;
    }

    .field_list_wrap .field_li .tel {
        font-size: 12px;
        color: #999;
        line-height: 20px;
    }

    .field_list_wrap .field_li .address {
        font-size: 12px;
        color: #999;
        line-height: 16px;
    }

    .field_list_wrap .field_fy {
        text-align: center;
    }

    .field_list_wrap .field_fy_wrap {
        overflow: hidden;
        margin: 10px auto;
        display: inline-block;
    }

    .field_list_wrap .field_fy a {
        height: 18px;
        line-height: 18px;
        padding: 0 5px;
        font-size: 12px;
        color: #0099e9;
        float: left;
        margin: 0 2px;
        border: 1px solid #ebebeb;
    }

    .field_list_wrap .field_fy a:hover {
        border-color: #0099e9;
        cursor: pointer;
    }

    .field_list_wrap .field_fy .dian {
        padding: 0 2px;
        text-align: center;
        color: #999;
        border: none;
    }

    .field_list_wrap .field_fy .current {
        background: #0099e9;
        border: 1px solid #0099e9;
        color: #fff;
    }

    .field_list_wrap_big .close {
        position: absolute;
        top: 50%;
        -webkit-transform: translate(0, -50%);
        -ms-transform: translate(0, -50%);
        -moz-transform: translate(0, -50%);
        transform: translate(0, -50%);
        width: 17px;
        height: 62px;
        border: 1px solid #cacaca;
        border-right: none;
        /* margin-top: 210px; */
        background: url('${ctx}/image/activity/field_IconSprite5.png');
        border-radius: 2px 0 0 2px;
        cursor: pointer;
    }

    .field_list_wrap_big .close span {
        width: 7px;
        height: 11px;
        background: url('${ctx}/image/activity/field_IconSprite4.png') no-repeat 0px 0;
        margin: 25px 5px;
        display: inline-block;
    }

    .post_map {
        width: 100%;
        height: 512px; /*float:left;*/
    }

    .activity-location .address-name {
        font-weight: normal;
        font-size: 16px;
        color: #000;
        max-width: 280px;
    }

    .activity-location .address-name-label {
        width: 42px;
        vertical-align: text-top;
    }

    .activity-location .address-name-value {
        max-width: 260px;
    }

    .activity-location .set-address {
        color: red
    }

    .activity-location a:hover {
        color: red
    }

    .activity-location table td {
        padding-top: 10px;
    }

    .post_site_K {
        width: 265px;
        height: 36px;
        border: 1px solid #d9d9d9;
        display: inline-block;
    }

    .post_site_K input {
        width: calc(100% - 100px);
        height: 100%;
        line-height: 100%;
        border: none;
        font-size: 14px;
        color: #444;
        float: left;
        margin: 8px 0 0 15px;
        margin-top: 0px;
    }

    .post_site_K span {
        display: block;
        cursor: pointer;
        width: 72px;
        height: 20px;
        line-height: 19px;
        font-size: 14px;
        color: #666;
        text-align: right;
        border-left: 1px solid #d9d9d9;
        float: left;
        margin-top: 8px;
        background: url(${ctx}/image/activity/address_icon3.png) no-repeat 10px 1px;
    }
</style>
<div class="map-warp">
    <!-- 城市_区域_地图 -->
    <div class="layui-form-item mb5">
        <label class="layui-form-label">居住地址</label>
        <div class="layui-inline" style="float: left; width: calc(100% - 183px);">
            <div class="layui-input-inline">
                <select name="hCityId" id="cityId" lay-verify="city" lay-filter="city">
                    <option value="">选择城市</option>
                    <c:forEach var="city" items="${citys}">
                        <option value="${city.id}">${city.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="hArea" lay-verify="area_select" id="areaSelect" lay-filter="area">
                    <option value="">选择区域</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input name="areaInput" type="text" id="areaInput" lay-verify="area_input"
                       placeholder="填写区域" class="layui-input" value="" style="display: none;"/>
            </div>
            <div class="post_site_K">
                <input type="text" placeholder="填写具体地址" id="place" name="hPlace" value="" readonly="readonly" lay-verify="place">
                <input type="hidden" name="hLat" id="lat"/>
                <input type="hidden" name="hLng" id="lng" lay-verify="lng"/>
                <span id="fadeIn" onclick="" style="display: none;cursor: pointer;">已标记</span>
            </div>
        </div>
    </div>

    <div class="layui-form-item mb5">
        <label class="layui-form-label">公司地址</label>
        <div class="layui-inline" style="float: left; width: calc(100% - 183px);">
            <div class="layui-input-inline">
                <select name="cCityId" id="sCityId" lay-verify="sCityId" lay-filter="sCityId">
                    <option value="">选择城市</option>
                    <c:forEach var="city" items="${citys}">
                        <option value="${city.id}">${city.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="cArea" lay-verify="area_select" id="sArea" lay-filter="sArea">
                    <option value="">选择区域</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input name="sAreaInput" type="text" id="sAreaInput" lay-verify="sAreaInput"
                       placeholder="填写区域" class="layui-input" value="" style="display: none;"/>
            </div>
            <div class="post_site_K">
                <input type="text" placeholder="填写具体地址" id="sPlace" name="cPlace" value="" readonly="readonly" lay-verify="sPlace">
                <input type="hidden" name="cLat" id="slat"/>
                <input type="hidden" name="cLng" id="slng" lay-verify="slng"/>
                <span id="sfadeIn" onclick="" style="display: none;cursor: pointer;">已标记</span>
            </div>
        </div>
    </div>

    <div id="mapDiv" class="layui-form-item ovh" style="display: none;">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <div id="allmap" class="post_map"></div>
            <div class="field_list_wrap_big">
                <div class="close" onclick="width_auto($(this));">
                    <span style="background: url('${ctx}/image/activity/field_IconSprite4.png') 0px 0px no-repeat scroll;"></span>
                </div>
                <div class="field_list_wrap">
                    <div class="top">场地列表</div>
                    <div class="field_box" id="panel">
                        <div style="position: relative;">
                            <ul class="field_ul"></ul>
                            <div class="field_fy" style="display: block;">
                                <div class="field_fy_wrap"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {

        txz.Map = {
            placeEle : null,
            latEle : null,
            lngEle : null,
            markFlag:null,
            _map: null,
            //初始化map对象
            _initMap: function () {
                var that = this;
                that._map = new BMap.Map("allmap", {
                    enableMapClick: false
                });
                that._map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
                that._map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
                that._map.enableScrollWheelZoom(true);
                // 添加带有定位的导航控件
                var navigationControl = new BMap.NavigationControl({
                    // 靠左上角位置
                    anchor: BMAP_ANCHOR_TOP_LEFT,
                    // LARGE类型
                    type: BMAP_NAVIGATION_CONTROL_LARGE,
                    // 启用显示定位
                    enableGeolocation: true
                });
                that._map.addControl(navigationControl);
            },
            //添加事件
            _addEvt: function (layForm) {
                var that = this;
                $("#fadeIn").click(function () {
                    $("#mapDiv").toggle(1000);
                });
                $("#sfadeIn").click(function () {
                    $("#mapDiv").toggle(1000);
                });
                $(".field_ul").delegate('.field_li', 'click', function (e) {
                    that._map.clearOverlays();//清空原来的标注
                    var $target = e.target;
                    var parent = $target.closest(".field_li");
                    $(parent).siblings(".field_li").removeClass("current_hover");
                    $(parent).addClass("current_hover");
                    var jsonStr = $(parent).attr("data-json");
                    var jsonObject = JSON.parse(jsonStr);
                    that._selectAddress(jsonObject, 'add');
                });

                $("#areaInput").blur(function () {
                    var value = $(this).val();
                    if (value != "") {
                        $("#mapDiv").show();
                        txz.Map._map.centerAndZoom(value, 15);
                        $("#place").removeAttr("readonly");
                    } else {
                        clearPlace();
                    }
                });

                $("#sAreaInput").blur(function () {
                    var value = $(this).val();
                    if (value != "") {
                        $("#mapDiv").show();
                        txz.Map._map.centerAndZoom(value, 15);
                        $("#sPlace").removeAttr("readonly");
                    } else {
                        clearPlace2();
                    }
                });

                $("#place").blur(function () {
                    that.placeEle = '#place';
                    that.lngEle = '#lng';
                    that.latEle = '#lat';
                    var value = $(this).val();
                    if (value != "") {
                        that._appendListData(null);
                    } else {
                        clearPlace();
                    }
                });

                $("#sPlace").blur(function () {
                    that.placeEle = '#sPlace';
                    that.lngEle = '#slng';
                    that.latEle = '#slat';
                    that.markFlag = '#sfadeIn';
                    var value = $(this).val();
                    if (value != "") {
                        that._appendListData2(null);
                    } else {
                        clearPlace2();
                    }
                });

                // 城市
                layForm.on('select(city)', function (data) {
                    var cityName = $('#cityId option[value="'+data.value+'"]')[0].label;
                    that._loadAreaData(cityName,'',layForm);
                    $('#mapDiv').show();
                    txz.Map._map.centerAndZoom(cityName, 12);
                    clearPlace();
                });

                layForm.on('select(sCityId)', function (data) {
                    var cityName = $('#sCityId option[value="'+data.value+'"]')[0].label;
                    that._loadAreaData2(cityName,'',layForm);
                    $('#mapDiv').show();
                    txz.Map._map.centerAndZoom(cityName, 12);
                    clearPlace2();
                });

                // 区域
                layForm.on('select(area)', function (data) {
                    var value = data.value;
                    if (value != "") {
                        txz.Map._map.centerAndZoom(value, 16);
                    }
                    clearPlace();
                });

                //起点区域
                layForm.on('select(sArea)', function (data) {
                    var value = data.value;
                    if (value != "") {
                        txz.Map._map.centerAndZoom(value, 16);
                    }
                    clearPlace2();
                });
            },
            //加载区域数据
            _loadAreaData: function (cityName, area, layForm) {
                var areaData = [];
                txz.ajaxRequest({
                    url:  '${ctx}/activity/activity/getAreaByCityName.do',
                    type: 'POST',
                    async: false, // 使用同步的方法
                    params:  {
                        "cityName": cityName
                    },
                    callBack:function (data) {
                        var str = '',areaData = data;
                        if (data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                if (area && area == data[i].name) {
                                    str += "<option value = '" + data[i].name + "' selected='selected'>" + data[i].name + "</option>";
                                } else {
                                    str += "<option value = '" + data[i].name + "'>" + data[i].name + "</option>";
                                }
                            }
                            $("#areaSelect").html(str);
                            $("#place").removeAttr("readonly");
                        } else {
                            str += "<option value = ''>选择区域</option>";
                            $("#areaSelect").html(str);
                        }
                        //刷新layForm
                        layForm.render('select');
                        //判断并显示
                        if(data.length > 0){
                            $("#areaSelect").parent().show();
                            $('#areaInput').hide();
                        }else{
                            $("#areaSelect").parent().hide();
                            $('#areaInput').show();
                        }
                    }
                });
                return areaData.length;
            },

            //加载起点区域数据
            _loadAreaData2: function (cityName, area, layForm) {
                var areaData = [];
                txz.ajaxRequest({
                    url:  '${ctx}/activity/activity/getAreaByCityName.do',
                    type: 'POST',
                    async: false, // 使用同步的方法
                    params:  {
                        "cityName": cityName
                    },
                    callBack:function (data) {
                        var str = '',areaData = data;
                        if (data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                if (area && area == data[i].name) {
                                    str += "<option value = '" + data[i].name + "' selected='selected'>" + data[i].name + "</option>";
                                } else {
                                    str += "<option value = '" + data[i].name + "'>" + data[i].name + "</option>";
                                }
                            }
                            $("#sArea").html(str);
                            $("#sPlace").removeAttr("readonly");
                        } else {
                            str += "<option value = ''>选择区域</option>";
                            $("#sArea").html(str);
                        }
                        //刷新layForm
                        layForm.render('select');
                        //判断并显示
                        if(data.length > 0){
                            $("#sArea").parent().show();
                            $('#sAreaInput').hide();
                        }else{
                            $("#sArea").parent().hide();
                            $('#sAreaInput').show();
                        }
                    }
                });
                return areaData.length;
            },

            //加载map
            _centerAndZoom: function () {
                var that = this;
                if ($('#areaInput').val()) {
                    $("#mapDiv").show();
                    that._map.centerAndZoom($('#areaInput').val(), 16);
                    $("#place").removeAttr("readonly");
                    that._appendListData(null);
                }

                if ($('#place').val()) {
                    var $select = $("[name=hCityId]").siblings(".layui-form-select");
                    var cityName = $select.find(".layui-select-title .layui-input").val();
                    $("#mapDiv").show();
                    that._map.centerAndZoom(cityName, 16);
                    that._appendListData(null);
                    $('.field_list_wrap_big').removeClass('open');
                }

                if ($('#sAreaInput').val()) {
                    $("#mapDiv").show();
                    that._map.centerAndZoom($('#sAreaInput').val(), 16);
                    $("#sPlace").removeAttr("readonly");
                    that._appendListData2(null);
                }

                if ($('#sPlace').val()) {
                    var $select = $("[name=cCityId]").siblings(".layui-form-select");
                    var cCityName = $select.find(".layui-select-title .layui-input").val();
                    $("#mapDiv").show();
                    that._map.centerAndZoom(cCityName, 16);
                    that._appendListData2(null);
                    $('.field_list_wrap_big').removeClass('open');
                }
            },
            //跳转页面
            _gotoPage: function(obj) {
                var that = this;
                $("field_fy_wrap a").removeClass("current");
                $(obj).addClass("current");
                var page = parseInt($(obj).text());
                that._appendListData(page);
            },
            _gotoPage2: function(obj) {
                var that = this;
                $("field_fy_wrap a").removeClass("current");
                $(obj).addClass("current");
                var page = parseInt($(obj).text());
                that._appendListData2(page);
            },
            //初始化表单数据
            _initFormData: function (opts) {
                var that = this;
                var data = opts.data, layForm = opts.layForm;
                $('#cityId').val(data.cityId);
                $('#areaInput').val(data.areaInput);
                $('#place').val(data.place);
                $('#lat').val(data.lat);
                $('#lng').val(data.lng);

                $('#sCityId').val(data.cCityId);
                $('#sAreaInput').val(data.cAreaInput);
                $('#sPlace').val(data.cPlace);
                $('#slat').val(data.clat);
                $('#slng').val(data.clng);

                var hCityName = $('#cityId option[value="'+data.cityId+'"]')[0].label;
                var cCityName = $('#sCityId option[value="'+data.cCityId+'"]')[0].label;
                //加载区域数据
                hCityName && that._loadAreaData(hCityName, data.areaInput,layForm)
                cCityName && that._loadAreaData2(cCityName,data.cAreaInput,layForm);
            },
            _selectAddress:function(obj, type) {
                var that = this;
                var lng = obj.location.lng;
                var lat = obj.location.lat;
                var new_point = new BMap.Point(lng, lat);
                var marker = new BMap.Marker(new_point); // 创建标注，为要查询的地方对应的经纬度

                $(that.placeEle).val(obj.name);
                $(that.latEle).val(lat);
                $(that.lngEle).val(lng);

                var array = new Array();
                array.push("<div class='activity-location'><div class='address-name'>" + obj.name + "</div>");
                array.push("<table cellspacing='0' ><tbody>");
                if (obj.address != undefined) {
                    array.push("<tr><td class='address-name-label'>地址：</td><td class='address-name-value'>" + obj.address + "</td></tr>");
                }
                // 		array.push("<tr><td></td><td><a class='set-address' data-json='" + JSON.stringify(obj)
                // 				+ "' onclick='clickFunction($(this))'>选为我的活动地点</a></td></tr>");
                array.push("</tbody></table>");
                array.push("</div>");

                that._map.addOverlay(marker);
                that._map.panTo(new_point);

                openInfo(array.join(""), lng, lat);

                addClickHandler(array.join(""), marker);

                function addClickHandler(content, marker) {
                    marker.addEventListener("click", function (e) {
                        var p = e.target;
                        openInfo(content, p.getPosition().lng, p.getPosition().lat);
                    });
                }

                function openInfo(content, lng, lat) {
                    var point = new BMap.Point(lng, lat);
                    var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
                    that._map.openInfoWindow(infoWindow, point); //开启信息窗口

                }

                if (type != "edit") {
                    util.layerMsgSuccess("标记成功")
                    if (that.markFlag != '#sfadeIn')
                    {
                        toggleFadeIn();
                    } else
                    {
                        toggleFadeIn2();
                    }
                }
            },
            _appendListData:function(page) {
                var that = this;
                var $select = $("[name=hCityId]").siblings(".layui-form-select");
                var cityName = $select.find(".layui-this").text();

                var $select = $("#areaSelect").siblings(".layui-form-select");
                var areaName = $select.find(".layui-select-title .layui-input").val();
                if (areaName == "") {
                    areaName = $("#areaInput").val();
                }
                areaName = areaName + $("#place").val();
                txz.ajaxRequest({
                    url: '${ctx}/map/map/search.do',
                    type: 'POST',
                    async: false, // 使用同步的方法
                    params:  {
                        region: cityName,
                        query: areaName,
                        pageNum: page
                    },
                    callBack:function (data) {
                        var dataResults = data.data.results;
                        var array = new Array();
                        $(".field_ul").html("");
                        if (dataResults.length > 0) {
                            for (var i = 0; i < dataResults.length; i++) {
                                var jsonStr = JSON.stringify(dataResults[i]);
                                jsonStr = jsonStr.replace(new RegExp("\"", "gm"), "&quot;");
                                jsonStr = jsonStr.replace(new RegExp("'", "gm"), "&#39;");
                                array.push("<li class='field_li' data-json='" + jsonStr + "'>");
                                array.push("<a href='javascript:void(0);'>");
                                array.push("<div class='box'><h2>" + dataResults[i].name + "</h2>");
                                if (dataResults[i].address != undefined) {
                                    array.push("<p class='address'>地址:" + dataResults[i].address + "</p>");
                                }
                                array.push("</div>");
                                array.push("<div class='number'>" + (i + 1) + "</div></a></li>");
                            }

                            $(".field_ul").append(array.join(""));

                            $(".field_fy_wrap").html("");
                            var pageArray = new Array();
                            for (var i = 0; i < data.data.totalPage; i++) {
                                if (data.data.pageNum == i) {
                                    pageArray.push("<a class='current' onclick='txz.Map._gotoPage($(this))'>" + (i + 1) + "</a>");
                                } else {
                                    pageArray.push("<a class='' onclick='txz.Map._gotoPage($(this))'>" + (i + 1) + "</a>");
                                }
                            }
                            $(".field_fy_wrap").append(pageArray.join(""));

                            $('.field_list_wrap_big').addClass('open');

//                            var location = dataResults[0].location;
//                            if (location != undefined) {
//                                $("#lat").val(location.lat);
//                                $("#lng").val(location.lng);
//                                that._map.centerAndZoom(new BMap.Point(location.lng, location.lat), 18);
//                                that._selectAddress(dataResults[0], "edit");
//                            }
                        } else {
                            $(".field_fy_wrap").html("没有找到符合的数据");

                            var lng = $("#lng").val();
                            var lat = $("#lat").val();
                            if (lng != '' && lat != '' && '${member.id}' != "") {
                                that._map.centerAndZoom(new BMap.Point(lng, lat), 18);
                                txz.ajaxRequest({
                                    url: '${ctx}/map/map/getAddress.do',
                                    type: 'POST',
                                    async: false, // 使用同步的方法
                                    params:  {
                                        x: lng,
                                        y: lat
                                    },
                                    callBack:function (data) {
                                        var dataResults = data.data.result;
                                        var resultObject = {
                                            location: dataResults.location,
                                            name: $("#place").val(),
                                            address: dataResults.formatted_address + dataResults.sematic_description
                                        };
                                        that._selectAddress(eval(resultObject), "edit");
                                    }
                                })
                            }
                        }

                    }
                })

                toggleFadeIn();
            },
            _appendListData2:function(page) {
                var that = this;
                var $select = $("[name=cCityId]").siblings(".layui-form-select");
                var cityName = $select.find(".layui-this").text();

                var $select = $("#sArea").siblings(".layui-form-select");
                var areaName = $select.find(".layui-select-title .layui-input").val();
                if (areaName == "") {
                    areaName = $("#sAreaInput").val();
                }
                areaName = areaName + $("#sPlace").val();
                txz.ajaxRequest({
                    url: '${ctx}/map/map/search.do',
                    type: 'POST',
                    async: false, // 使用同步的方法
                    params:  {
                        region: cityName,
                        query: areaName,
                        pageNum: page
                    },
                    callBack:function (data) {
                        var dataResults = data.data.results;
                        var array = new Array();
                        $(".field_ul").html("");
                        if (dataResults.length > 0) {
                            for (var i = 0; i < dataResults.length; i++) {
                                var jsonStr = JSON.stringify(dataResults[i]);
                                jsonStr = jsonStr.replace(new RegExp("\"", "gm"), "&quot;");
                                jsonStr = jsonStr.replace(new RegExp("'", "gm"), "&#39;");
                                array.push("<li class='field_li' data-json='" + jsonStr + "'>");
                                array.push("<a href='javascript:void(0);'>");
                                array.push("<div class='box'><h2>" + dataResults[i].name + "</h2>");
                                if (dataResults[i].address != undefined) {
                                    array.push("<p class='address'>地址:" + dataResults[i].address + "</p>");
                                }
                                array.push("</div>");
                                array.push("<div class='number'>" + (i + 1) + "</div></a></li>");
                            }

                            $(".field_ul").append(array.join(""));

                            $(".field_fy_wrap").html("");
                            var pageArray = new Array();
                            for (var i = 0; i < data.data.totalPage; i++) {
                                if (data.data.pageNum == i) {
                                    pageArray.push("<a class='current' onclick='txz.Map._gotoPage2($(this))'>" + (i + 1) + "</a>");
                                } else {
                                    pageArray.push("<a class='' onclick='txz.Map._gotoPage2($(this))'>" + (i + 1) + "</a>");
                                }
                            }
                            $(".field_fy_wrap").append(pageArray.join(""));

                            $('.field_list_wrap_big').addClass('open');

//                            var location = dataResults[0].location;
//                            if (location != undefined) {
//                                $("#lat").val(location.lat);
//                                $("#lng").val(location.lng);
//                                that._map.centerAndZoom(new BMap.Point(location.lng, location.lat), 18);
//                                that._selectAddress(dataResults[0], "edit");
//                            }
                        } else {
                            $(".field_fy_wrap").html("没有找到符合的数据");

                            var lng = $("#slng").val();
                            var lat = $("#slat").val();
                            if (lng != '' && lat != '' && '${cRoute.id}' != "") {
                                that._map.centerAndZoom(new BMap.Point(lng, lat), 18);
                                txz.ajaxRequest({
                                    url: '${ctx}/map/map/getAddress.do',
                                    type: 'POST',
                                    async: false, // 使用同步的方法
                                    params:  {
                                        x: lng,
                                        y: lat
                                    },
                                    callBack:function (data) {
                                        var dataResults = data.data.result;
                                        var resultObject = {
                                            location: dataResults.location,
                                            name: $("#sPlace").val(),
                                            address: dataResults.formatted_address + dataResults.sematic_description
                                        };
                                        that._selectAddress(eval(resultObject), "edit");
                                    }
                                })
                            }
                        }

                    }
                })
                toggleFadeIn2();
            },
            //加载脚本
            _loadJs: function (cb) {
                typeof cb === 'function' && cb();
            },
            init: function (opts) {
                var that = this;
                //加载脚本
                that._loadJs(function () {
                    that._initMap();
                    that._initFormData(opts);
                    that._addEvt(opts.layForm);
                    that._centerAndZoom();
                })
            }
        };
    });
    function toggleFadeIn() {
        if ($("#lat").val() != "") {
            $("#fadeIn").css("display", "block");
        } else {
            $("#fadeIn").css("display", "none");
        }
    }
    function toggleFadeIn2() {
        if ($("#slat").val() != "") {
            $("#sfadeIn").css("display", "block");
        } else {
            $("#sfadeIn").css("display", "none");
        }
    }

    function width_auto(that) {
        var listWrap = $(that).closest('.field_list_wrap_big');
        listWrap.toggleClass('open');
    }

    function clearPlace() {
        $("#place").val("");
        $("#lat").val("");
        $("#lng").val("");
        $(".field_ul").html("");
        $(".field_fy_wrap").html("");
        $('.field_list_wrap_big').removeClass('open');
        toggleFadeIn();
    }
    function clearPlace2() {
        $("#sPlace").val("");
        $("#slat").val("");
        $("#slng").val("");
        $(".field_ul").html("");
        $(".field_fy_wrap").html("");
        $('.field_list_wrap_big').removeClass('open');
        toggleFadeIn2();
    }


</script>